<template>
  <div>
    <div>
      <!-- 添加 -->
      <el-card class="box-card">
        <div>
          <span class="iconfont icon-dingdan"></span>
          <span>品牌管理列表</span>
          <el-button
            style="float: right"
            type="button"
            size="small"
            @click="goAddPage"
            >添加</el-button
          >
        </div>
      </el-card>
    </div>

    <el-table
      ref="multipleTable"
      :data="productlist"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>

      <el-table-column prop="id" label="编号" width="100"> </el-table-column>
      <el-table-column label="品牌名称" prop="name"> </el-table-column>

      <el-table-column label="品牌首字母" prop="first_letter">
      </el-table-column>

      <el-table-column label="排序" prop="sort"> </el-table-column>
      <el-table-column label="品牌制造商" align="center">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.factory_status"
            :active-value="1"
            :inactive-value="0"
             @change="updadeShow(scope.row.id)"
          >
          
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="是否显示" align="center">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.show_status"
            :active-value="1"
            :inactive-value="0" 
            @change="dadeShow(scope.row.id)"
          >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="相关" align="center" width="200">
        <template slot-scope="scope">
         <p>商品：{{scope.row.product_count}}</p>
          <p>评价：{{scope.row.product_comment_count}}</p>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="goupdatePage(scope.row.id)">编辑</el-button>
          <el-button type="danger" size="mini">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
     <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="listQuery.pageNum"
      :page-sizes="[2, 5, 10, 15]"
      :page-size="listQuery.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>
<script>
import { getbrand,fetchbrand,Onebrand} from "@/api/product";
export default {
  name: "brand",
  data: function () {
    return {
      productlist: [],
      total: 0, //总数量
      name: "",
      multipleTable: [],
      listQuery: {
        pageSize: 5,
        pageNum: 1,
        
      },
    };
  },
  mounted() {
    //调用函数
    this.gett();
  },
  methods: {
    updadeShow(id){
      fetchbrand({id,show_status:this.productlist.show_status}).then(res => {
        if(res.status === 200){
          this.$message({
              message:'修改状态成功',
              type:'success'
          })
        }
      })

    },
    dadeShow(id){
      Onebrand({id,factory_status:this.productlist.factory_status}).then(res => {
        if(res.status === 200){
          this.$message({
              message:'修改状态成功',
              type:'success'
          })
        }
      })

    },
    //修改一页的数据量
    handleSizeChange(val) {
      console.log("修改一页的数据量", val);
      this.listQuery.pageSize = val;
      this.listQuery.pageNum = 1;
      this.gett();
    },
    handleCurrentChange(val) {
      console.log("修改当前页页码", val);
      this.listQuery.pageNum = val;
      this.gett();
    },
   
    //跳转到添加页面
    goAddPage() {
      this.$router.push("/pms/brandadd");
    },
    //跳转到修改页面
    goupdatePage(id) {
      this.$router.push("/pms/updatebrand/" + id);
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    async gett() {
      var res = await getbrand(this.listQuery);
      this.productlist = res.data;
      this.total = res.total;
      console.log(this.productlist,this.total);
    },
  },
};
</script>

<style>
</style>